<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_teacher extends CI_Model {
    /**
     * 继承父类
     */
    function __construct(){
        parent::__construct();
    }
    /**
     * 添加教师信息
     * @param  [type] $str [description]
     * @return [type]      [description]
     */
    public function teacher_add($str){
        $into='';
        $k='';
        foreach ($str as $key => $value) {
            $k.=$k?(" , ".$key):$key;
            $into.=$into?(" , '".$value."'"):("'".$value."'");
        }
        $query="INSERT INTO stu_teacher (".$k.") VALUES (".$into.")";
        $this->db->query($query);
        return $this->db->insert_id();
    }
    /**
     * 直接查找教师基本信息
     */
    public function teacher_search($str=array()){
        $where='';
        foreach ($str as $key => $value) {
            $where.=$where?(" AND ".$key."='".$value."'"):($key."='".$value."'");
        }
        $query="SELECT * FROM stu_teacher WHERE ".$where."ORDER BY t_id  DESC";
        $result=$this->db->query($query);
        return $result->result();
    }
    /**
     * 查询教师信息
     * @param  [type] $params [description]
     * @return [type]         [description]
     */
    public function teacher_login_search($str){
        $where='';
        foreach ($str as $key => $value) {
            $where.=$where?(" AND ".$key."='".$value."'"):($key."='".$value."'");
        }
        $query="SELECT * FROM stu_t_login INNER JOIN stu_teacher ON stu_t_login.tl_id=stu_teacher.t_id WHERE ".$where;
        $result=$this->db->query($query);
        return $result->result();
    }
    /**
     * 添加学生登录信息
     * @param  [type] $str [description]
     * @return [type]      [description]
     */
    public function teacher_login_add($str){
        $into='';
        $k='';
        foreach ($str as $key => $value) {
            if($value){
                $k.=$k?(" , ".$key):$key;
                $into.=$into?(" , '".$value."'"):("'".$value."'");
            }
        }
        $query="INSERT INTO stu_t_login (".$k.") VALUES (".$into.")";
        return $this->db->query($query);
    }
}